﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoDbObject;
using SZJT.Utility.DataSource;

namespace Colligate.DataSource.DriverTraining.Maintain
{
    class MtanScheduleInfo:BaseLegoModule
    {

          private const string TABLE_SCHEDULE_INFO = "MtanScheduleInfo";

          public MtanScheduleInfo(IDataSourceLayer dataLayer)
            : base(new string[] { TABLE_SCHEDULE_INFO }, dataLayer)
        {
        }

        #region 返回Lego模块涉及到的数据名称的结构信息
        /// <summary>
        /// 返回Lego模块涉及到的数据名称的结构信息
        /// </summary>
        /// <param name="strDataName">基础表名称</param>
        /// <returns>表结构信息</returns>
        override public IFieldInfo[] GetStructInfo(string strDataName)
        {
            // 建立IFieldInfo列表
            // CFieldInfo(字段名, 类型, 长度, 索引, 状态, 字段说明, 字段帮助, 显示的格式化字符串, 字段宽度, 关联记录)
            // 类型： text，byte，short，long，single，double，currency，date，logical，memo，binary
            // 索引： 0 无索引，1 重复索引，2 唯一索引，3 关键字段
            // 状态： 0 系统字段，>1显示信息的字段， 2 用于标识记录名称的字段

            IFieldInfo[] tableStructInfo;
            switch (strDataName)
            {
                case "MtanScheduleInfo":	 // 驾校作息时间信息
                    tableStructInfo = new IFieldInfo[10];
                    tableStructInfo[0] = new CFieldInfo("fScheduleGuid", "text", 36, 2, 0, "驾校作息时间信息", "驾校作息时间信息", "", 52, 0);
                    tableStructInfo[1] = new CFieldInfo("fScheduleDate", "date", 0, 0, 1, "日期", "日期", "", 52, 0);
                    tableStructInfo[2] = new CFieldInfo("fIsWorkingDay", "text", 1, 0, 1, "是否为工作日[T:是|F:否]", "是否为工作日[T:是|F:否]", "", 52, 0);
                    tableStructInfo[3] = new CFieldInfo("fMorningStart", "single", 0, 0, 1, "上午开始时间，6代表6点整，7.5代表7点半，7.15代表7点一刻", "上午开始时间，6代表6点整，7.5代表7点半，7.15代表7点一刻", "", 52, 0);
                    tableStructInfo[4] = new CFieldInfo("fMorningHours", "long", 0, 0, 1, "上午工作小时数", "上午工作小时数", "", 52, 0);
                    tableStructInfo[5] = new CFieldInfo("fAfternoonStart", "single", 0, 0, 1, "下午开始时间，格式同上午开始时间", "下午开始时间，格式同上午开始时间", "", 52, 0);
                    tableStructInfo[6] = new CFieldInfo("fAfternoonHours", "long", 0, 0, 1, "下午工作小时数", "下午工作小时数", "", 52, 0);
                    tableStructInfo[7] = new CFieldInfo("fEveningStart", "single", 0, 0, 1, "晚上开始时间，格式同上午开始时间", "晚上开始时间，格式同上午开始时间", "", 52, 0);
                    tableStructInfo[8] = new CFieldInfo("fEveningHours", "long", 0, 0, 1, "晚上工作小时数", "晚上工作小时数", "", 52, 0);
                    tableStructInfo[9] = new CFieldInfo("fScheduleMemo", "memo", 0, 0, 1, "日期备注，比如：国庆节，驾校1周年庆", "日期备注，比如：国庆节，驾校1周年庆", "", 52, 0);
                    break;
                default: tableStructInfo = null; break;
            }
            return tableStructInfo;
        }
        #endregion

        // 驾校作息时间信息
        public IDBDataObject GetScheduleInfoData(string scheduleGUID)
        {
            string tableName = GetStructGlobalName(TABLE_SCHEDULE_INFO);
            return DataLayer.GetDBDataObject(tableName, string.Format("fScheduleGuid = '{0}'", scheduleGUID));
        }

        public IDBBigObjectSet GetLastScheduleInfoData()
        {
            return DataLayer.GetDBBigObjectSet(GetStructGlobalName(TABLE_SCHEDULE_INFO), "", "fScheduleDate asc");
        }

        public IDBBigObjectSet GetScheduleByDate(string scheduleDateStart, string scheduleDateEnd)
        {

            QueryFilter queryFilter = new QueryFilter();
            queryFilter.AddFilter("fScheduleDate", scheduleDateStart, "Datediff(d,{0},'{1}')<=0");
            queryFilter.AddFilter("fScheduleDate", scheduleDateEnd, "Datediff(d,{0},'{1}')>=0", true);

            //queryFilter.AddFilter("fIsWorkingDay", QueryFilter.FilterType.TEXT, studentSex);
            //queryFilter.AddFilter("fMorningStart", studentID, "{0} like '%{1}%'");
            //queryFilter.AddFilter("fMorningHours", studentMobile, "{0} like '%{1}%'");
            //queryFilter.AddFilter("fAfternoonStart", QueryFilter.FilterType.TEXT, studentStatus);
            //queryFilter.AddFilter("fEveningStart", QueryFilter.FilterType.TEXT, studentStatus);
            //queryFilter.AddFilter("fEveningHours", QueryFilter.FilterType.TEXT, studentStatus);
            //queryFilter.AddFilter("fScheduleMemo", QueryFilter.FilterType.TEXT, studentStatus);
           
            return DataLayer.GetDBBigObjectSet(GetStructGlobalName(TABLE_SCHEDULE_INFO), queryFilter.FilterString, "fScheduleDate");
        }

       
    }
}
